package com.yonyou.pmclouds.procedure.rmiimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.procedure.entity.ProceprojectVO;
import com.yonyou.pmclouds.procedure.mapper.ProceprojectMapper;
import com.yonyou.pmclouds.procedure.rmiitf.ProceprojectQryService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ProceprojectQryService.class, version = ApplicationConsts.APPLICATION_VERSION)
public class ProceprojectQryServiceImpl implements ProceprojectQryService {
    @Autowired
    private ProceprojectMapper proceprojectMapper ;
    @Override
    public ProceprojectVO selectProceprojectByObj(ProceprojectVO obj){
        return proceprojectMapper.selectProceprojectByObj(obj);
    }
    @Override
    public ProceprojectVO selectProceprojectById(String id){
        return proceprojectMapper.selectProceprojectById(id);
    }


    @Override
    public ProceprojectVO[] selectProceprojectByProjectId(String id) {
        ProceprojectVO[] proceprojectVOS = proceprojectMapper.selectProceprojectByProjectId(id);
        return proceprojectVOS;
    }

    @Override
    public Map<String, List<ProceprojectVO>> queryRefProjectByProjectIds(String[] pkProjects) {
        if(pkProjects == null || pkProjects.length <= 0){
            return null;
        }

        ProceprojectVO[] refProjectVOS = proceprojectMapper.queryRefProjectByProjectIds(pkProjects);

        if(refProjectVOS == null || refProjectVOS.length <= 0){
            return null;
        }

        Map<String, List<ProceprojectVO>> refProjectMap = new HashMap<>();
        for(ProceprojectVO refProjectVO : refProjectVOS){

            List<ProceprojectVO> refProjects = refProjectMap.get(refProjectVO.getPkProject());
            if(refProjects != null){
                refProjects.add(refProjectVO);
            }else {
                refProjects = new ArrayList<>();
                refProjects.add(refProjectVO);
                refProjectMap.put(refProjectVO.getPkProject(), refProjects);
            }
        }

        return refProjectMap;
    }
}